package com.add;

import com.lineage.DatabaseFactory;
import com.lineage.server.utils.PerformanceTimer;
import com.lineage.server.utils.SQLUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class ItemTimeTableadd {
  private static final Log _log = LogFactory.getLog(ItemTimeTableadd.class);
  
  public static final Map<Integer, L1ItemTimeadd> TIME = new HashMap<>();
  
  private static ItemTimeTableadd _instance;
  
  public static ItemTimeTableadd get() {
    if (_instance == null)
      _instance = new ItemTimeTableadd(); 
    return _instance;
  }
  
  public void load() {
    PerformanceTimer timer = new PerformanceTimer();
    Connection con = null;
    PreparedStatement pstm = null;
    ResultSet rs = null;
    try {
      con = DatabaseFactory.get().getConnection();
      pstm = con.prepareStatement("SELECT * FROM `w_物品日期限制`");
      rs = pstm.executeQuery();
      while (rs.next()) {
        int key = rs.getInt("道具编号");
        Timestamp next_reset_time = rs.getTimestamp("物品时间限制使用");
        L1ItemTimeadd itemTime = new L1ItemTimeadd(next_reset_time);
        TIME.put(Integer.valueOf(key), itemTime);
      } 
    } catch (SQLException e) {
      _log.error(e.getLocalizedMessage(), e);
    } finally {
      SQLUtil.close(rs);
      SQLUtil.close(pstm);
      SQLUtil.close(con);
    } 
  }
}
